import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class LeetCode1154 {
    public static void main(String[] args) {
        System.out.println(dayOfYear("2012-01-02"));
    }

    private static final int[] MONTH_DAY_NUMBER = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    public static int dayOfYear(String date) {
        List<Integer> yearMonthDay = Arrays.stream(date.split("-")).map(Integer::parseInt).collect(Collectors.toList());
        int monthDay = yearMonthDay.get(2);
        int month = yearMonthDay.get(1);
        int year = yearMonthDay.get(0);

        int day;
        if (month > 2 && (((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0))) {
            day = 1;
        } else {
            day = 0;
        }

        for (int i = 1; i < month; i++) {
            day += MONTH_DAY_NUMBER[i];
        }

        day += monthDay;

        return day;
    }

}
